﻿/*
 * Created by SharpDevelop.
 * User: DELL
 * Date: 07/28/2012
 * Time: 20:57
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.ComponentModel.Composition;
using System.Windows;
using System.Windows.Input;
using Microsoft.Practices.Prism.Commands;
using Microsoft.Practices.Prism.Events;
using Microsoft.Practices.Prism.ViewModel;

using IntoNails.Infrastructure.EventAggregators;

namespace IntoNails
{
    [Export(typeof (ShellViewModel))]
    [PartCreationPolicy(CreationPolicy.NonShared)]
    public partial class ShellViewModel : NotificationObject
    {
        #region Fields

        private readonly IEventAggregator _eventAggregator;

        private bool _unlockRibbonBar = true;
        private bool _showRibbonBar;

        #endregion

        // This is where any view model logic for the shell would go.
        [ImportingConstructor]
        public ShellViewModel(IEventAggregator eventAggregator)
        {
            this._eventAggregator = eventAggregator;
            this._eventAggregator.GetEvent<UnLockRibbonBarEventAggregators>().Subscribe(this.OnLockRibbonBarEventSubscribed, ThreadOption.UIThread);
            this._eventAggregator.GetEvent<ShowRibbonBarEventAggregators>().Subscribe(this.OnShowRibbonBarEventSubscribed, ThreadOption.UIThread);
            this._eventAggregator.GetEvent<SystemShutdownEventAggregator>().Subscribe(this.OnSystemShutdownEventSubscribed, ThreadOption.PublisherThread);

            this.ExitCommand = new DelegateCommand(this.ExecuteExitCommand);
        }

        #region Properties

        public bool UnlockRibbonBar
        {
            get { return this._unlockRibbonBar; }
            set
            {
                this._unlockRibbonBar = value;
                base.RaisePropertyChanged(() => UnlockRibbonBar);
            }
        }

        public bool ShowRibbonBar
        {
            get { return this._showRibbonBar; }
            set
            {
                this._showRibbonBar = value;
                base.RaisePropertyChanged(() => ShowRibbonBar);
            }
        }

        #endregion

        public ICommand ExitCommand { get; private set; }

        private void ExecuteExitCommand()
        {
            Application.Current.Shutdown();
        }
    }
}
